Next: , Previous: Extracting source code, Up: Working With Source Code


14.5 Evaluating code blocks

Code blocks can be evaluated1 and the results placed in the Org-mode buffer. By default, evaluation is only turned on for emacs-lisp code blocks, however support exists for evaluating blocks in many languages. See Languages for a list of supported languages. See Structure of code blocks for information on the syntax used to define a code block.

There are a number of ways to evaluate code blocks. The simplest is to press C-c C-c or C-c C-v e with the point on a code block2. This will call the org-babel-execute-src-block function to evaluate the block and insert its results into the Org-mode buffer.

It is also possible to evaluate named code blocks from anywhere in an Org-mode buffer or an Org-mode table. #+call (or synonymously #+function or #+lob) lines can be used to remotely execute code blocks located in the current Org-mode buffer or in the “Library of Babel” (see Library of Babel). These lines use the following syntax.

     #+call: <name>(<arguments>) <header arguments>
     #+function: <name>(<arguments>) <header arguments>
     #+lob: <name>(<arguments>) <header arguments>
<name>
The name of the code block to be evaluated.
<arguments>
Arguments specified in this section will be passed to the code block.
<header arguments>
Header arguments can be placed after the function invocation. See Header arguments for more information on header arguments.

Footnotes

[1] Whenever code is evaluated there is a potential for that code to do harm. Org-mode provides a number of safeguards to ensure that it only evaluates code with explicit confirmation from the user. For information on these safeguards (and on how to disable them) see Code evaluation security.

[2] The org-babel-no-eval-on-ctrl-c-ctrl-c variable can be used to remove code evaluation from the C-c C-c key binding.